/**
 * login node file
 */

var Action = new Function();

Action.prototype.init = function(req, res){
	switch(req.method) {
		case 'POST': this.post(req, res); break;
		default: this.other(req, res); break;
	}
};

Action.prototype.post = function(req, res){
	var email = req.body.email;
	var password = req.body.password;
	var login = new (Services('login'))(email, password, {
		success: function(data){
			res.send(JSON.stringify(data));
			res.end();
		},
		error: function(code, message){
			res.send(this.toString());
			res.end();
		}
	});
};

Action.prototype.other = function(req, res){
	res.writeHead(404, {
		'Content-Type': 'text/plain',
		'Trailer': 'Content-MD5'
	});
	res.end();
};

module.exports = Action;